#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node 
{
    int a,f,d;
};
void solve()
{
    int n;
    cin>>n;
    vector<vector<int>> v(n+1);
    int x,y;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int s=1;
    while(s<=n&&v[s].size()!=2)s++;
    if(s==n+1)
    {
        cout<<"NO"<<endl;
        return ;
    }
    cout<<"YES"<<endl;
    queue<node> q;
    q.push({v[s][0],s,0});
    q.push({v[s][1],s,1});
    while(!q.empty())
    {
        int t=q.front().a,f=q.front().f,d=q.front().d;
        if(d)cout<<t<<" "<<f<<endl;
        else cout<<f<<" "<<t<<endl;
        q.pop();
        for(int i=0;i<v[t].size();i++)
            if(v[t][i]!=f)q.push({v[t][i],t,!d});
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}